home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / kerberos / pc / krb_libk.lha / Lib / KRB / CRTICKET.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-01  |  4.4 KB  |  142 lines

  1. /* 
  2.  * $Source: /mit/kerberos/src/lib/krb/RCS/create_ticket.c,v $
  3.  * $Author: jtkohl $
  4.  *
  5.  * Copyright 1985, 1986, 1987, 1988 by the Massachusetts Institute
  6.  * of Technology.
  7.  *
  8.  * For copying and distribution information, please see the file
  9.  * <mit-copyright.h>.
  10.  */
  11.  
  12. #ifndef lint
  13. static char rcsid_create_ticket_c[] =
  14. "$Header: create_ticket.c,v 4.11 89/03/22 14:43:23 jtkohl Exp $";
  15. #endif /* lint */
  16.  
  17. #include <mit_copy.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <des.h>
  21. #include <krb.h>
  22. #include <prot.h>
  23. #include <sys/socket.h>
  24.  
  25. /*
  26.  * Create ticket takes as arguments information that should be in a
  27.  * ticket, and the KTEXT object in which the ticket should be
  28.  * constructed.  It then constructs a ticket and returns, leaving the
  29.  * newly created ticket in tkt.
  30. #ifndef NOENCRYPTION
  31.  * The data in tkt->dat is encrypted in the server's key.
  32. #endif
  33.  * The length of the ticket is a multiple of
  34.  * eight bytes and is in tkt->length.
  35.  *
  36.  * If the ticket is too long, the ticket will contain nulls.
  37.  * The return value of the routine is undefined.
  38.  *
  39.  * The corresponding routine to extract information from a ticket it
  40.  * decomp_ticket.  When changes are made to this routine, the
  41.  * corresponding changes should also be made to that file.
  42.  *
  43.  * The packet is built in the following format:
  44.  * 
  45.  *             variable
  46.  * type            or constant       data
  47.  * ----            -----------       ----
  48.  *
  49.  * tkt->length        length of ticket (multiple of 8 bytes)
  50.  * 
  51. #ifdef NOENCRYPTION
  52.  * tkt->dat:
  53. #else
  54.  * tkt->dat:        (encrypted in server's key)
  55. #endif
  56.  * 
  57.  * unsigned char    flags           namely, HOST_BYTE_ORDER
  58.  * 
  59.  * string        pname           client's name
  60.  * 
  61.  * string        pinstance       client's instance
  62.  * 
  63.  * string        prealm           client's realm
  64.  * 
  65.  * 4 bytes        paddress       client's address
  66.  * 
  67.  * 8 bytes        session           session key
  68.  * 
  69.  * 1 byte        life           ticket lifetime
  70.  * 
  71.  * 4 bytes        time_sec       KDC timestamp
  72.  * 
  73.  * string        sname           service's name
  74.  * 
  75.  * string        sinstance       service's instance
  76.  * 
  77.  * <=7 bytes        null           null pad to 8 byte multiple
  78.  *
  79.  */
  80.  
  81. int krb_create_ticket(tkt, flags, pname, pinstance, prealm, paddress,
  82.           session, life, time_sec, sname, sinstance, key)
  83.     KTEXT   tkt;                /* Gets filled in by the ticket */
  84.     unsigned char flags;        /* Various Kerberos flags */
  85.     char    *pname;             /* Principal's name */
  86.     char    *pinstance;         /* Principal's instance */
  87.     char    *prealm;            /* Principal's authentication domain */
  88.     long    paddress;           /* Net address of requesting entity */
  89.     char    *session;           /* Session key inserted in ticket */
  90.     short   life;               /* Lifetime of the ticket */
  91.     long    time_sec;           /* Issue time and date */
  92.     char    *sname;             /* Service Name */
  93.     char    *sinstance;         /* Instance Name */
  94.     C_Block key;                /* Service's secret key */
  95. {
  96.     Key_schedule key_s;
  97.     register char *data;        /* running index into ticket */
  98.  
  99.     tkt->length = 0;            /* Clear previous data  */
  100.     flags |= HOST_BYTE_ORDER;   /* ticket byte order   */
  101.     bcopy((char *) &flags,(char *) (tkt->dat),sizeof(flags));
  102.     data = ((char *)tkt->dat) + sizeof(flags);
  103.     (void) strcpy(data, pname);
  104.     data += 1 + strlen(pname);
  105.     (void) strcpy(data, pinstance);
  106.     data += 1 + strlen(pinstance);
  107.     (void) strcpy(data, prealm);
  108.     data += 1 + strlen(prealm);
  109.     bcopy((char *) &paddress, data, 4);
  110.     data += 4;
  111.  
  112.     bcopy((char *) session, data, 8);
  113.     data += 8;
  114.     *(data++) = (char) life;
  115.     /* issue time */
  116.     bcopy((char *) &time_sec, data, 4);
  117.     data += 4;
  118.     (void) strcpy(data, sname);
  119.     data += 1 + strlen(sname);
  120.     (void) strcpy(data, sinstance);
  121.     data += 1 + strlen(sinstance);
  122.  
  123.     /* guarantee null padded ticket to multiple of 8 bytes */
  124.     bzero(data, 7);
  125.     tkt->length = ((data - ((char *)tkt->dat) + 7)/8)*8;
  126.  
  127.     /* Check length of ticket */
  128.     if (tkt->length > (sizeof(KTEXT_ST) - 7)) {
  129.         bzero((char *)tkt->dat, tkt->length);
  130.         tkt->length = 0;
  131.         return KFAILURE /* XXX */;
  132.     }
  133.  
  134. #ifndef NOENCRYPTION
  135.     /* Encrypt the ticket in the services key */        
  136.     key_sched(key,key_s);
  137.     pcbc_encrypt((C_Block *)tkt->dat,(C_Block *)tkt->dat,
  138.                  (long) tkt->length,key_s,key,1);
  139. #endif /* !NOENCRYPTION */
  140.     return 0;
  141. }
  142.